<template>
  <div id="user">
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column fixed prop="id" label="id"> </el-table-column>
      <el-table-column prop="username" label="昵称"> </el-table-column>
      <el-table-column prop="password" label="密码"> </el-table-column>
      <el-table-column prop="email" label="邮箱"> </el-table-column>

      <el-table-column prop="createTime" label="创建时间"> </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="deleteRow(scope.$index, tableData)"
            type="text"
            size="small"
          >
            移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getAllUser, deleteUser } from "../../api/interface";
export default {
  data() {
    return {
      tableData: [],
    };
  },
  created() {
    this.getData();
  },
  methods: {
    deleteRow(index, rows) {
      deleteUser(rows[index].id)
        .then((res) => {
          this.$notify({
            title: "删除成功",
            message: "",
            type: "success",
          });
          this.getData();
        })
        .catch((error) => {});
    },
    getData() {
      let _this = this;
      getAllUser()
        .then((res) => {
          _this.tableData = res.data.data;
        })
        .catch((error) => {
          console.log(error);
        });
    },
  },
};
</script>

<style lang="less" scoped>
#user {
  width: 100%;
  height: 100%;
}
</style>